﻿

Ext.define('Kaseya.web.widgets.composite.scheduler.KSchedulerNew', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.kschedulernew',

    // @private
    ONCE: 'ONCE',
    MINUTELY: 'MINUTES',
    HOURLY: 'HOURLY',
    DAILY: 'DAILY',
    WEEKLY: 'WEEKLY',
    MONTHLY: 'MONTHLY',
    YEARLY: 'YEARLY',

    // @private
    SUNDAY: 'SUNDAY',
    MONDAY: 'MONDAY',
    TUESDAY: 'TUESDAY',
    WEDNESDAY: 'WEDNESDAY',
    THURSDAY: 'THURSDAY',
    FRIDAY: 'FRIDAY',
    SATURDAY: 'SATURDAY',
    WEEKDAY: 'WEEKDAY',
    WEEKENDDAY: 'WEEKEND_DAY',
    DAY: 'DAY',

    // @private
    MINUTES: 1,
    HOURS: 2,
    DAYS: 3,

    // @private
    FIRST: 'FIRST',
    SECOND: 'SECOND',
    THIRD: 'THIRD',
    FOURTH: 'FOURTH',
    LAST: 'LAST',

    // @private
    JANUARY: 1,
    FEBRUARY: 2,
    MARCH: 3,
    APRIL: 4,
    MAY: 5,
    JUNE: 6,
    JULY: 7,
    AUGUST: 8,
    SEPTEMBER: 9,
    OCTOBER: 10,
    NOVEMBER: 11,
    DECEMBER: 12,

    // @private
    MONTHLY_ON_DAY: 0,
    MONTHLY_ON_THE: 1,

    // @private
    YEARLY_ON_DAY: 0,
    YEARLY_ON_THE: 1,

    // @private
    END_NEVER: '1',
    END_AFTER: '2',
    END_AT: '3',

    // @private
    SKIP_IF_OFFLINE: 'skipifoffline',
    POWER_UP_IF_OFFLINE: 'powerupifoffline',
    EXECUTE_WHEN_ONLINE: 'execwhennextonline',

    // Agent or Server Time
    // @private
    SCHED_IN_AGENT_TIME: 'schedinagenttime',

    border: false,
    bodyBorder: false,
    layout: 'anchor',
    anchor: '-20',

    //styling constants
    numberInputWidth: 40,

    initComponent: function () {
        this.applyMetaField();
        this.metaConfig = this.getMetaObject();

        //We don't want the panel to have a header or anything, so we need to remove its title
        delete this.title;

        //Recurrence
        var recurrenceOptions = [];

        if (this.findMetaFieldInObject('disableonetimerecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.OnceRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.ONCE,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disableminutesrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.MinutelyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.MINUTELY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disablehourlyrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.HourlyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.HOURLY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disabledailyrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.DailyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.DAILY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disableweeklyrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.WeeklyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.WEEKLY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disablemonthlyrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.MontlyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.MONTHLY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        if (this.findMetaFieldInObject('disableyearlyrecurrencepattern', this.metaConfig).defaultValue != "true") {
            recurrenceOptions.push({
                boxLabel: Ext.ux.LangMgr.SchedulerControl.YearlyRecurrenceLabel,
                name: 'recurrence',
                inputValue: this.YEARLY,
                listeners: {
                    'change': {
                        fn: this.changeRecurrence,
                        scope: this
                    }
                }
            });
        }

        //Set pre-select the first recurrenceOption
        if (recurrenceOptions.length > 0) {
            recurrenceOptions[0].checked = true;
        }

        this.recurrence = {
            xtype: 'fieldset',
            title: Ext.ux.LangMgr.SchedulerControl.RecurrenceSectionTitle,
            hideLabels: true,
            height: 330,
            items: {
                xtype: 'radiogroup',
                name: 'recurrenceOptions',
                columns: 1,
                items: recurrenceOptions
            }
        };

        this.useAgentTime = {
            xtype: 'fieldset',
            title: Ext.ux.LangMgr.SchedulerControl.TimePreference,
            hideLabels: true,
            items: {
                xtype: 'checkbox',
                name: 'schedinagenttime',
                boxLabel: Ext.ux.LangMgr.SchedulerControl.ScheduleAsAgentTime,
                inputValue: this.SCHED_IN_AGENT_TIME,
                checked: this.findMetaFieldInObject('defaultschedinagenttime', this.metaConfig).defaultValue == "true",
                listeners: {
                    'change': {
                        fn: function (_field, _checked) {
                            if (_checked) {
                                this.Update('schedinagenttime', 'Y');
                            }
                            else {
                                this.Update('schedinagenttime', 'N');
                            }
                        },
                        scope: this
                    }
                }
            }
        };


        //Schedule Options
        var scheduleCards = [];

        var runAt = {
            layout: 'column',
            defaults: {
                border: false
            },
            items: [{
                width: 240,
                layout: 'anchor',
                items: {
                    xtype: 'timefield',
                    format: ShellFinder().Date.DefaultTimeFormat,
                    name: 'run_at',
                    fieldLabel: Ext.ux.LangMgr.SchedulerControl.RunAt,
                    width: 220,
                    listWidth: 210,
                    value: Ext.util.Format.date(new Date(), ShellFinder().Date.DefaultTimeFormat),
                    listeners: {
                        'change': {
                            fn: function (_field, _newVal, _oldVal) {
                                var date = Ext.Date.parse(_newVal, _field.format);
                                if (date) {
                                    this.Update('starttimefrom', Ext.Date.format(date, 'c'));
                                }
                                //update all the other controls
                                var runAts = this.find('name', 'run_at');
                                for (var i = 0; i < runAts.length; i++)
                                    runAts[i].setValue(_newVal);
                                //We changed the starting point, so we need to update the end point
                                this.UpdateEndDateTime();
                            },
                            scope: this
                        },
                        'select': {
                            fn: function (_field, value, options) {
                                //_field.setValue(_record.data[_field.valueField]);
                                _field.setValue(value);
                                //var date = Ext.Date.parse(_record.data[_field.valueField], _field.format);
                                //if (date) {
                                this.Update('starttimefrom', Ext.Date.format(value, 'c'));
                                //}
                                //update all the other controls
                                var runAts = this.find('name', 'run_at');
                                for (var i = 0; i < runAts.length; i++)
                                    runAts[i].setValue(value);
                                //We changed the starting point, so we need to update the end point
                                this.UpdateEndDateTime();
                            },
                            scope: this
                        }
                    }
                }
            }, {
                layout: 'anchor',
                width: 155,
                bodyStyle: Ext.isIE ? 'padding-top: 1px' : null,
                items: {
                    xtype: 'numberfield',
                    hideTrigger: true,
                    allowDecimals: false,
                    name: 'distribution_window_value',
                    fieldLabel: Ext.ux.LangMgr.SchedulerControl.DistributionWindow,
                    width: this.numberInputWidth ? this.numberInputWidth : 240,
                    enableKeyEvents: true,
                    width: 150,
                    hideLabel: this.findMetaFieldInObject('disabledistributionwindow', this.metaConfig).defaultValue == "true",
                    hidden: this.findMetaFieldInObject('disabledistributionwindow', this.metaConfig).defaultValue == "true",
                    value: this.findMetaFieldInObject('disabledistributionwindow', this.metaConfig).defaultValue == "true" ? 0 : 1,
                    listeners: {
                        'keyup': {
                            fn: function (_field) {
                                var runAts = this.find('name', 'run_at');
                                if (runAts && runAts.length) {
                                    for (var i = 0; i < runAts.length; i++) {
                                        var date = Ext.Date.parse(runAts[i].value, runAts[i].format);
                                        this.Update('starttimefrom', Ext.Date.format(date, 'c'));
                                    }
                                }
                                var distributionWindows = this.find('name', 'distribution_window_value');
                                for (var i = 0; i < distributionWindows.length; i++)
                                    distributionWindows[i].setValue(_field.getValue());
                                //We changed the end interval, update the end datetime
                                this.UpdateEndDateTime();
                            },
                            scope: this
                        }
                    }
                }
            }, {
                width: 80,
                layout: 'anchor',
                hideLabels: true,
                items: {
                    xtype: 'combo',
                    name: 'distribution_window_interval',
                    store: new Ext.data.SimpleStore({
                        fields: ['name', 'value'],
                        data: [[Ext.ux.LangMgr.SchedulerControl.DistributionWindowMinutes, this.MINUTES], [Ext.ux.LangMgr.SchedulerControl.DistributionWindowHours, this.HOURS], [Ext.ux.LangMgr.SchedulerControl.DistributionWindowDays, this.DAYS]]
                    }),
                    displayField: 'name',
                    valueField: 'value',
                    mode: 'local',
                    forceSelection: true,
                    triggerAction: 'all',
                    selectOnFocus: true,
                    resizeable: true,
                    hidden: this.findMetaFieldInObject('disabledistributionwindow', this.metaConfig).defaultValue == "true",
                    width: 50,
                    value: this.HOURS,
                    listeners: {
                        'select': {
                            fn: function (_field, value, options) {
                                var distributionIntervals = this.find('name', 'distribution_window_interval');
                                for (var i = 0; i < distributionIntervals.length; i++)
                                    distributionIntervals[i].setValue(value);
                                //We changed the end interval, update the end datetime
                                this.UpdateEndDateTime();
                            },
                            scope: this
                        }
                    }
                }
            }]
        }

        if (this.findMetaFieldInObject('disableonetimerecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.ONCE,
            title: Ext.ux.LangMgr.SchedulerControl.OnceSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                xtype: 'datefield',
                name: 'start_on',
                format: ShellFinder().Date.DefaultDateFormat,
                fieldLabel: Ext.ux.LangMgr.SchedulerControl.On,
                width: 220,
                value: new Date(),
                listeners: {
                    'change': {
                        fn: function (_field, _newVal, _oldVal) {
                            this.Update('startdatefrom', Ext.Date.format(_newVal, 'c'));
                            var startDate = this.find('name', 'start_on');
                            for (var i = 0; i < startDate.length; i++)
                                if (startDate[i].getValue() != _newVal) startDate[i].setValue(_newVal);
                            //We changed the start point, so we need to update the end point now
                            this.UpdateEndDateTime();
                        },
                        scope: this
                    },
                    'select': {
                        fn: function (_field, _newVal) {
                            _field.setValue(_newVal);
                            if (Ext.isIE8) {
                                _field.fireEvent('change', _field, _newVal);
                            }
                        },
                        scope: this
                    }
                }
            }]
        });
        if (this.findMetaFieldInObject('disableminutesrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.MINUTELY,
            title: Ext.ux.LangMgr.SchedulerControl.MinutelyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    layout: 'anchor',
                    width: 200,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_minutely_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 200,
                        listeners: {
                            'blur': {
                                fn: function (_field) {
                                    if (_field.getValue() == '') {
                                        _field.setValue('1');
                                    }
                                }
                            },
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringminutesinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Minutes
                }]
            }]
        });
        if (this.findMetaFieldInObject('disablehourlyrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.HOURLY,
            title: Ext.ux.LangMgr.SchedulerControl.HourlyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    layout: 'anchor',
                    width: 155,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_hourly_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 150,
                        listeners: {
                            'blur': {
                                fn: function (_field) {
                                    if (_field.getValue() == '') {
                                        _field.setValue('1');
                                    }
                                }
                            },
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringhoursinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Hours,
                    width: 50
                }]
            }]
        });
        if (this.findMetaFieldInObject('disabledailyrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.DAILY,
            title: Ext.ux.LangMgr.SchedulerControl.DailyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    layout: 'anchor',
                    width: 155,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_daily_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 150,
                        listeners: {
                            'blur': {
                                fn: function (_field) {
                                    if (_field.getValue() == '') {
                                        _field.setValue('1');
                                    }
                                }
                            },
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringdaysinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Days,
                    width: 50
                }]
            }]
        });
        if (this.findMetaFieldInObject('disableweeklyrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.WEEKLY,
            title: Ext.ux.LangMgr.SchedulerControl.WeeklyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    layout: 'anchor',
                    width: 155,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_weekly_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 150,
                        listeners: {
                            'blur': {
                                fn: function (_field) {
                                    if (_field.getValue() == '') {
                                        _field.setValue('1');
                                    }
                                }
                            },
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringweeksinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Weeks,
                    width: 50
                }]
            }, {
                xtype: 'checkboxgroup',
                name: 'days_of_the_week',
                allowBlank: false,
                fieldLabel: Ext.ux.LangMgr.SchedulerControl.On,
                anchor: '-20',
                columns: Ext.isIE ? [100, 100, 100, 100] : 4,
                items: [{
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Sunday,
                    inputValue: this.SUNDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('sundayflag', 'Y');
                                else
                                    this.Update('sundayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Monday,
                    inputValue: this.MONDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('mondayflag', 'Y');
                                else
                                    this.Update('mondayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Tuesday,
                    inputValue: this.TUESDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('tuesdayflag', 'Y');
                                else
                                    this.Update('tuesdayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Wednesday,
                    inputValue: this.WEDNESDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('wednesdayflag', 'Y');
                                else
                                    this.Update('wednesdayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Thursday,
                    inputValue: this.THURSDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('thursdayflag', 'Y');
                                else
                                    this.Update('thursdayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Friday,
                    inputValue: this.FRIDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('fridayflag', 'Y');
                                else
                                    this.Update('fridayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }, {
                    name: 'days_of_week',
                    boxLabel: Ext.ux.LangMgr.SchedulerControl.Saturday,
                    inputValue: this.SATURDAY,
                    listeners: {
                        'change': {
                            fn: function (_field, _checked) {
                                if (_checked)
                                    this.Update('saturdayflag', 'Y');
                                else
                                    this.Update('saturdayflag', 'N');
                            },
                            scope: this
                        }
                    }
                }]
            }]
        });
        if (this.findMetaFieldInObject('disablemonthlyrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.MONTHLY,
            title: Ext.ux.LangMgr.SchedulerControl.MontlyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    width: 155,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_monthly_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 150,
                        listeners: {
                            'blur': {
                                fn: function (_field) {
                                    if (_field.getValue() == '') {
                                        _field.setValue('1');
                                    }
                                }
                            },
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringmonthsinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Months,
                    width: 50
                }]
            }, {
                items: [{
                    border: false,
                    defaults: {
                        border: false,
                        bodyStyle: 'padding-top: 5px; padding-bottom: 5px'
                    },
                    layout: {
                        type: 'table',
                        columns: 3
                    },
                    //width: 200,
                    items: [{
                        bodyStyle: 'padding-left: 15px; padding-right: 5px',
                        width: 75,
                        items: {
                            xtype: 'radio',
                            name: 'monthly',
                            inputValue: this.MONTHLY_ON_DAY,
                            boxLabel: Ext.ux.LangMgr.SchedulerControl.MonthlyOptionOnDay,
                            checked: true,
                            context: this,
                            handler: function (_field, checked) {
                                if (checked) {
                                    _field.context.Update('monthlyintervaltype', _field.inputValue);
                                }
                            }
                        }
                    }, {
                        width: 50,
                        items: {
                            xtype: 'numberfield',
                            hideTrigger: true,
                            allowDecimals: false,
                            name: 'month_day',
                            width: this.numberInputWidth,
                            enableKeyEvents: true,
                            value: 1,
                            minValue: 1,
                            maxValue: 31,
                            width: 45,
                            listeners: {
                                'keyup': {
                                    fn: function (_field) {
                                        if (_field.getValue() >= 0) {
                                            var montlyInterval = this.find('name', 'monthly');
                                            for (var i = 0; i < montlyInterval.length; i++)
                                                montlyInterval[i].setValue(montlyInterval[i].inputValue == this.MONTHLY_ON_DAY);

                                            if (montlyInterval[i].inputValue == this.MONTHLY_ON_DAY) {
                                                montlyInterval[i].fireEvent('check', montlyInterval[i], true);
                                            }
                                            this.Update('monthday', _field.getValue());
                                        }
                                    },
                                    scope: this
                                }
                            }
                        }
                    }, {
                        items: {
                            width: 60,
                            xtype: 'label',
                            text: Ext.ux.LangMgr.SchedulerControl.MonthlyOptionOfTheMonth
                        }
                    }]
                }, {
                    border: false,
                    defaults: {
                        border: false,
                        bodyStyle: 'padding-top: 5px; padding-bottom: 5px'
                    },
                    layout: {
                        type: 'table',
                        columns: 3
                    },
                    items: [{
                        bodyStyle: 'padding-left: 15px; padding-right: 5px',
                        items: {
                            xtype: 'radio',
                            name: 'monthly',
                            inputValue: this.MONTHLY_ON_THE,
                            boxLabel: Ext.ux.LangMgr.SchedulerControl.MonthlyOptionOnThe,
                            context: this,
                            handler: function (_field, checked) {
                                if (checked) {
                                    _field.context.Update('monthlyintervaltype', _field.inputValue);
                                }
                            }
                        }
                    }, {
                        width: 120,
                        items: {
                            xtype: 'combo',
                            name: 'monthly_specific_occurrence',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.First, this.FIRST], [Ext.ux.LangMgr.SchedulerControl.Second, this.SECOND], [Ext.ux.LangMgr.SchedulerControl.Third, this.THIRD], [Ext.ux.LangMgr.SchedulerControl.Fourth, this.FOURTH], [Ext.ux.LangMgr.SchedulerControl.Last, this.LAST]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.FIRST,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var montlyInterval = this.find('name', 'monthly');
                                        for (var i = 0; i < montlyInterval.length; i++)
                                            montlyInterval[i].setValue(montlyInterval[i].inputValue == this.MONTHLY_ON_THE);
                                        this.Update('monthlyspecificoccurrence', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }, {
                        width: 120,
                        items: {
                            xtype: 'combo',
                            name: 'monthly_specific_day',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.Sunday, this.SUNDAY], [Ext.ux.LangMgr.SchedulerControl.Monday, this.MONDAY], [Ext.ux.LangMgr.SchedulerControl.Tuesday, this.TUESDAY], [Ext.ux.LangMgr.SchedulerControl.Wednesday, this.WEDNESDAY], [Ext.ux.LangMgr.SchedulerControl.Thursday, this.THURSDAY], [Ext.ux.LangMgr.SchedulerControl.Friday, this.FRIDAY], [Ext.ux.LangMgr.SchedulerControl.Saturday, this.SATURDAY], [Ext.ux.LangMgr.SchedulerControl.Weekday, this.WEEKDAY], [Ext.ux.LangMgr.SchedulerControl.WeekendDay, this.WEEKENDDAY], [Ext.ux.LangMgr.SchedulerControl.Day, this.DAY]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.SUNDAY,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var montlyInterval = this.find('name', 'monthly');
                                        for (var i = 0; i < montlyInterval.length; i++)
                                            montlyInterval[i].setValue(montlyInterval[i].inputValue == this.MONTHLY_ON_THE);
                                        this.Update('monthlyspecificday', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }]
                }]
            }]
        });
        if (this.findMetaFieldInObject('disableyearlyrecurrencepattern', this.metaConfig).defaultValue != "true") scheduleCards.push({
            xtype: 'fieldset',
            id: this.id + '_' + this.YEARLY,
            title: Ext.ux.LangMgr.SchedulerControl.YearlyOptionsSectionTitle,
            defaults: {
                border: false
            },
            items: [runAt, {
                layout: {
                    type: 'table',
                    columns: 2
                },
                items: [{
                    border: false,
                    layout: 'anchor',
                    width: 200,
                    bodyStyle: Ext.isIE ? 'padding-top: 2px' : null,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'run_yearly_every',
                        fieldLabel: Ext.ux.LangMgr.SchedulerControl.Every,
                        width: this.numberInputWidth,
                        enableKeyEvents: true,
                        value: 1,
                        minValue: 1,
                        maxValue: 999,
                        width: 200,
                        listeners: {
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) this.Update('recurringyearsinterval', _field.getValue());
                                    this.validateDistributionWindow();
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    xtype: 'label',
                    text: Ext.ux.LangMgr.SchedulerControl.Years
                }]
            }, {
                items: [{
                    border: false,
                    defaults: {
                        border: false,
                        bodyStyle: 'padding-top: 5px; padding-bottom: 5px'
                    },
                    layout: {
                        type: 'table',
                        columns: 3
                    },
                    items: [{
                        bodyStyle: 'padding-left: 15px; padding-right: 5px',
                        items: {
                            xtype: 'radio',
                            name: 'yearly',
                            inputValue: this.YEARLY_ON_DAY,
                            boxLabel: Ext.ux.LangMgr.SchedulerControl.On,
                            checked: true,
                            context: this,
                            handler: function (_field, checked) {
                                if (checked) {
                                    _field.context.Update('yearlyintervaltype', _field.inputValue);
                                }
                            }
                        }
                    }, {
                        width: 125,
                        items: {
                            xtype: 'combo',
                            name: 'yearly_specific_month',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.January, this.JANUARY], [Ext.ux.LangMgr.SchedulerControl.February, this.FEBRUARY], [Ext.ux.LangMgr.SchedulerControl.March, this.MARCH], [Ext.ux.LangMgr.SchedulerControl.April, this.APRIL], [Ext.ux.LangMgr.SchedulerControl.May, this.MAY], [Ext.ux.LangMgr.SchedulerControl.June, this.JUNE], [Ext.ux.LangMgr.SchedulerControl.July, this.JULY], [Ext.ux.LangMgr.SchedulerControl.August, this.AUGUST], [Ext.ux.LangMgr.SchedulerControl.September, this.SEPTEMBER], [Ext.ux.LangMgr.SchedulerControl.October, this.OCTOBER], [Ext.ux.LangMgr.SchedulerControl.November, this.NOVEMBER], [Ext.ux.LangMgr.SchedulerControl.December, this.DECEMBER]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.JANUARY,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var yearlyInterval = this.find('name', 'yearly');
                                        for (var i = 0; i < yearlyInterval.length; i++)
                                            yearlyInterval[i].setValue(yearlyInterval[i].inputValue == this.YEARLY_ON_DAY);
                                        this.Update('yearlyspecificmonth', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }, {
                        width: this.numberInputWidth ? this.numberInputWidth : 200,
                        items: {
                            xtype: 'numberfield',
                            hideTrigger: true,
                            allowDecimals: false,
                            name: 'yearly_day',
                            width: this.numberInputWidth ? this.numberInputWidth : 200,
                            enableKeyEvents: true,
                            value: 1,
                            width: 200,
                            listeners: {
                                'keyup': {
                                    fn: function (_field) {
                                        if (_field.getValue() >= 0) {
                                            var yearlyInterval = this.find('name', 'yearly');
                                            for (var i = 0; i < yearlyInterval.length; i++)
                                                yearlyInterval[i].setValue(yearlyInterval[i].inputValue == this.YEARLY_ON_DAY);
                                            this.Update('yearday', _field.getValue());
                                        }
                                    },
                                    scope: this
                                }
                            }
                        }
                    }]
                }, {
                    border: false,
                    defaults: {
                        border: false,
                        bodyStyle: 'padding-top: 5px; padding-bottom: 5px'
                    },
                    layout: {
                        type: 'table',
                        columns: 5
                    },
                    items: [{
                        bodyStyle: 'padding-left: 15px; padding-right: 5px',
                        items: {
                            xtype: 'radio',
                            name: 'yearly',
                            inputValue: this.YEARLY_ON_THE,
                            boxLabel: Ext.ux.LangMgr.SchedulerControl.On,
                            context: this,
                            handler: function (_field, checked) {
                                if (checked) {
                                    _field.context.Update('yearlyintervaltype', _field.inputValue);
                                }
                            }
                        }
                    }, {
                        width: 120,
                        items: {
                            xtype: 'combo',
                            name: 'year_specific_occurrence',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.First, this.FIRST], [Ext.ux.LangMgr.SchedulerControl.Second, this.SECOND], [Ext.ux.LangMgr.SchedulerControl.Third, this.THIRD], [Ext.ux.LangMgr.SchedulerControl.Fourth, this.FOURTH], [Ext.ux.LangMgr.SchedulerControl.Last, this.LAST]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.FIRST,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var yearlyInterval = this.find('name', 'yearly');
                                        for (var i = 0; i < yearlyInterval.length; i++)
                                            yearlyInterval[i].setValue(yearlyInterval[i].inputValue == this.YEARLY_ON_THE);
                                        this.Update('yearlyspecificoccurrence', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }, {
                        width: 120,
                        items: {
                            xtype: 'combo',
                            name: 'year_specific_day',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.Sunday, this.SUNDAY], [Ext.ux.LangMgr.SchedulerControl.Monday, this.MONDAY], [Ext.ux.LangMgr.SchedulerControl.Tuesday, this.TUESDAY], [Ext.ux.LangMgr.SchedulerControl.Wednesday, this.WEDNESDAY], [Ext.ux.LangMgr.SchedulerControl.Thursday, this.THURSDAY], [Ext.ux.LangMgr.SchedulerControl.Friday, this.FRIDAY], [Ext.ux.LangMgr.SchedulerControl.Saturday, this.SATURDAY], [Ext.ux.LangMgr.SchedulerControl.Weekday, this.WEEKDAY], [Ext.ux.LangMgr.SchedulerControl.WeekendDay, this.WEEKENDDAY], [Ext.ux.LangMgr.SchedulerControl.Day, this.DAY]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.SUNDAY,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var yearlyInterval = this.find('name', 'yearly');
                                        for (var i = 0; i < yearlyInterval.length; i++)
                                            yearlyInterval[i].setValue(yearlyInterval[i].inputValue == this.YEARLY_ON_THE);
                                        this.Update('yearlyspecificday', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }, {
                        bodyStyle: 'padding-right: 3px',
                        items: {
                            xtype: 'label',
                            text: Ext.ux.LangMgr.SchedulerControl.YearlyOptionInMonth
                        }
                    }, {
                        width: 125,
                        items: {
                            xtype: 'combo',
                            name: 'year_specific_month2',
                            width: 100,
                            listWidth: 100,
                            store: new Ext.data.SimpleStore({
                                fields: ['name', 'value'],
                                data: [[Ext.ux.LangMgr.SchedulerControl.January, this.JANUARY], [Ext.ux.LangMgr.SchedulerControl.February, this.FEBRUARY], [Ext.ux.LangMgr.SchedulerControl.March, this.MARCH], [Ext.ux.LangMgr.SchedulerControl.April, this.APRIL], [Ext.ux.LangMgr.SchedulerControl.May, this.MAY], [Ext.ux.LangMgr.SchedulerControl.June, this.JUNE], [Ext.ux.LangMgr.SchedulerControl.July, this.JULY], [Ext.ux.LangMgr.SchedulerControl.August, this.AUGUST], [Ext.ux.LangMgr.SchedulerControl.September, this.SEPTEMBER], [Ext.ux.LangMgr.SchedulerControl.October, this.OCTOBER], [Ext.ux.LangMgr.SchedulerControl.November, this.NOVEMBER], [Ext.ux.LangMgr.SchedulerControl.December, this.DECEMBER]]
                            }),
                            displayField: 'name',
                            valueField: 'value',
                            queryMode: 'local',
                            forceSelection: true,
                            triggerAction: 'all',
                            selectOnFocus: true,
                            resizeable: true,
                            value: this.JANUARY,
                            listeners: {
                                'select': {
                                    fn: function (_combo, _record, _index) {
                                        var yearlyInterval = this.find('name', 'yearly');
                                        for (var i = 0; i < yearlyInterval.length; i++)
                                            yearlyInterval[i].setValue(yearlyInterval[i].inputValue == this.YEARLY_ON_THE);
                                        this.Update('yearlyspecificmonth2', _record.data[_combo.valueField]);
                                    },
                                    scope: this
                                }
                            }
                        }
                    }]
                }]
            }]
        });

        var scheduleOptionHeight = Ext.isIE ? 170 : 150;
        this.scheduleOptions = new Ext.panel.Panel({
            layout: 'card',
            border: false,
            height: scheduleOptionHeight,
            activeItem: 0,
            defaults: {
                height: scheduleOptionHeight,
                hideMode: 'offsets'
            },
            items: scheduleCards
        });

        //Start/End
        this.interval = new Ext.form.Label({
            xtype: 'label',
            name: 'interval',
            text: ''
        });

        this.startEndSection = new Ext.form.FieldSet({
            hidden: true,
            hideMode: 'offsets',
            title: Ext.ux.LangMgr.SchedulerControl.StartEndSectionTitle,
            height: 175,
            items: [{
                xtype: 'datefield',
                name: 'start_on',
                fieldLabel: Ext.ux.LangMgr.SchedulerControl.StartingOn,
                format: ShellFinder().Date.DefaultDateFormat,
                width: 220,
                value: new Date(),
                listeners: {
                    'change': {
                        fn: function (_field, _newVal, _oldVal) {
                            this.Update('startdatefrom', Ext.Date.format(_newVal, 'c'));
                            var startDate = this.find('name', 'start_on');
                            for (var i = 0; i < startDate.length; i++)
                                if (startDate[i].getValue() != _newVal) startDate[i].setValue(_newVal);
                            //We changed the start point, so we need to update the end point now
                            this.UpdateEndDateTime();
                        },
                        scope: this
                    },
                    'select': {
                        fn: function (_field, _newVal) {
                            _field.setValue(_newVal);
                            if (Ext.isIE8) {
                                _field.fireEvent('change', _field, _newVal);
                            }
                        },
                        scope: this
                    }
                }
            }, {
                border: false,
                defaults: {
                    border: false,
                    bodyStyle: 'padding-top: 5px; padding-bottom: 5px'
                },
                layout: {
                    type: 'table',
                    columns: 5
                },
                items: [{
                    colspan: 5,
                    items: {
                        xtype: 'label',
                        text: Ext.ux.LangMgr.SchedulerControl.EndingAfter + ':'
                    }
                }, {
                    bodyStyle: 'padding-left: 15px',
                    items: {
                        xtype: 'radio',
                        name: 'ending_after',
                        inputValue: this.END_NEVER,
                        boxLabel: Ext.ux.LangMgr.SchedulerControl.StartEndOptionNoEndDate,
                        checked: true,
                        context: this,
                        handler: function (_field, checked) {
                            if (checked) {
                                _field.context.Update('rangeofrecurrencetype', _field.inputValue);
                            }
                        }
                    }
                }, {
                    colspan: 4
                }, {
                    bodyStyle: 'padding-left: 15px',
                    items: {
                        xtype: 'radio',
                        name: 'ending_after',
                        inputValue: this.END_AFTER,
                        boxLabel: Ext.ux.LangMgr.SchedulerControl.StartEndOptionEndAfter + ':',
                        context: this,
                        handler: function (_field, checked) {
                            if (checked) {
                                _field.context.Update('rangeofrecurrencetype', _field.inputValue);
                            }
                        }
                    }
                }, {
                    width: this.numberInputWidth ? this.numberInputWidth : 260,
                    items: {
                        xtype: 'numberfield',
                        hideTrigger: true,
                        allowDecimals: false,
                        name: 'ending_after_occurrences',
                        width: this.numberInputWidth ? this.numberInputWidth : 260,
                        enableKeyEvents: true,
                        listeners: {
                            'keyup': {
                                fn: function (_field) {
                                    if (_field.getValue() >= 0) {
                                        var endAfterRadio = this.find('name', 'ending_after');
                                        for (var i = 0; i < endAfterRadio.length; i++)
                                            endAfterRadio[i].setValue(endAfterRadio[i].inputValue == this.END_AFTER);
                                        this.Update('rangeofrecurrenceendafterinterval', _field.getValue());
                                    }
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    items: this.interval
                }, {
                    colspan: 2
                }, {
                    bodyStyle: 'padding-left: 15px',
                    items: {
                        xtype: 'radio',
                        name: 'ending_after',
                        inputValue: this.END_AT,
                        boxLabel: Ext.ux.LangMgr.SchedulerControl.StartEndOptionEndingAt + ':',
                        context: this,
                        handler: function (_field, checked) {
                            if (checked) {
                                _field.context.Update('rangeofrecurrencetype', _field.inputValue);
                            }
                        }
                    }
                }, {
                    width: 125,
                    colspan: 2,
                    items: {
                        xtype: 'timefield',
                        format: ShellFinder().Date.DefaultTimeFormat,
                        name: 'ending_at_time',
                        width: 120,
                        listeners: {
                            'change': {
                                fn: function (_field, _newVal, _oldVal) {
                                    var endAfterRadio = this.find('name', 'ending_after');
                                    for (var i = 0; i < endAfterRadio.length; i++)
                                        endAfterRadio[i].setValue(endAfterRadio[i].inputValue == this.END_AT);

                                    //Get the ShellFinder().Date and Time for the endingAt option
                                    var endDate = null;
                                    //var endTime = Ext.Date.parse(_newVal, _field.format);
                                    var endTime = ParseDate(_newVal, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                                    var endDates = this.find('name', 'ending_at_date');
                                    for (var i = 0; i < endDates.length; i++)
                                        endDate = endDates[i].getValue();
                                    if (endDate) {
                                        endDate.setHours(endTime.getHours());
                                        endDate.setMinutes(endTime.getMinutes());
                                        endDate.setSeconds(endTime.getSeconds());
                                    }
                                    this.Update('rangeofrecurrenceenddatetime', Ext.Date.format(this.correctDateToServerTime(endDate), 'c'));
                                },
                                scope: this
                            },
                            'select': {
                                fn: function (_field, value, options) {
                                    _field.setValue(value);
                                    var endAfterRadio = this.find('name', 'ending_after');
                                    for (var i = 0; i < endAfterRadio.length; i++)
                                        endAfterRadio[i].setValue(endAfterRadio[i].inputValue == this.END_AT);

                                    //Get the ShellFinder().Date and Time for the endingAt option
                                    var endDate = null;
                                    //var endTime = Ext.Date.parse(value, _field.format);
                                    var endTime = ParseDate(value, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                                    var endDates = this.find('name', 'ending_at_date');
                                    for (var i = 0; i < endDates.length; i++)
                                        endDate = endDates[i].getValue();
                                    if (endDate) {
                                        endDate.setHours(endTime.getHours());
                                        endDate.setMinutes(endTime.getMinutes());
                                        endDate.setSeconds(endTime.getSeconds());
                                    }
                                    this.Update('rangeofrecurrenceenddatetime', Ext.Date.format(this.correctDateToServerTime(endDate), 'c'));
                                },
                                scope: this
                            }
                        }
                    }
                }, {
                    width: 20,
                    items: {
                        xtype: 'label',
                        text: Ext.ux.LangMgr.SchedulerControl.on
                    }
                }, {
                    items: {
                        xtype: 'datefield',
                        name: 'ending_at_date',
                        width: 220,
                        format: ShellFinder().Date.DefaultDateFormat,
                        listeners: {
                            'change': {
                                fn: function (_field, _newVal, _oldVal) {
                                    var endAfterRadio = this.find('name', 'ending_after');
                                    for (var i = 0; i < endAfterRadio.length; i++)
                                        endAfterRadio[i].setValue(endAfterRadio[i].inputValue == this.END_AT);

                                    //Get the ShellFinder().Date and Time for the endingAt option
                                    var endDate = _newVal;
                                    var endTime = null;
                                    var endTimes = this.find('name', 'ending_at_time');
                                    for (var i = 0; i < endTimes.length; i++)
                                        endTime = Ext.Date.parse(endTimes[i].getValue(), endTimes[i].format);
                                    if (endTime) {
                                        endDate.setHours(endTime.getHours());
                                        endDate.setMinutes(endTime.getMinutes());
                                        endDate.setSeconds(endTime.getSeconds());
                                    }
                                    this.Update('rangeofrecurrenceenddatetime', Ext.Date.format(this.correctDateToServerTime(endDate), 'c'));
                                },
                                scope: this
                            },
                            'select': {
                                fn: function (_field, _newVal) {
                                    _field.setValue(_newVal);
                                    if (Ext.isIE8) {
                                        _field.fireEvent('change', _field, _newVal);
                                    }
                                },
                                scope: this
                            }
                        }
                    }
                }]
            }]
        });


        var schedule = {
            layout: 'column',
            border: false,
            bodyBorder: false,
            defaults: {
                border: false
            },
            items: [{
                bodyStyle: 'padding-right:5px;',
                width: 150,
                items: [this.recurrence]
            }, {
                columnWidth: 1,
                layout: 'anchor',
                xtype: 'fieldset',
                hideLabels: true,
                hidden: this.findMetaFieldInObject('disableSchedInAgentTime', this.metaConfig).defaultValue == "true",
                items: this.useAgentTime
            }, {
                columnWidth: 1,
                layout: 'anchor',
                items: [this.scheduleOptions, this.startEndSection]
            }]
        }

        var padding = 'padding-left: 2px';
        if (Ext.isIE) padding = 'padding-left: 10px';
        //Execution Options
        this.executionOptions = {
            xtype: 'fieldset',
            title: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsSectionTitle,
            autoHeight: true,
            hideLabels: true,
            anchor: '100%',
            items: [			/*
			 {
			 xtype: 'radiogroup',
			 columns: 1,
			 style: padding,
			 items: [{
			 name: 'if_offline',
			 boxLabel: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsSkipIfOffline,
			 inputValue: this.SKIP_IF_OFFLINE,
			 checked: true,
			 listeners: {
			 'check': {
			 fn: function(_radio, _checked){
			 if (_checked)
			 this.Update(_radio.inputValue, 'Y');
			 else
			 this.Update(_radio.inputValue, 'N');
			 },
			 scope: this
			 }
			 }
			 }, {
			 name: 'if_offline',
			 boxLabel: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsIfOfflineExecuteImmediately,
			 inputValue: this.EXECUTE_WHEN_ONLINE,
			 listeners: {
			 'check': {
			 fn: function(_radio, _checked){
			 if (_checked)
			 this.Update(_radio.inputValue, 'Y');
			 else
			 this.Update(_radio.inputValue, 'N');
			 },
			 scope: this
			 }
			 }
			 }]
			 },
			 */
			{
			xtype: 'fieldset',
			border: false,
			bodyBorder: false,
			collapsible: false,
			autoHeight: true,
			items: [{
			    xtype: 'checkbox',
			    name: 'if_offline',
			    boxLabel: this.findMetaFieldInObject('disablepowerupifoffline', this.metaConfig).defaultValue == "true" ? Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsSkipIfOffline : Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsSkipIfOffline + " " + Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsSkipIfOfflineExplaination,
			    inputValue: this.SKIP_IF_OFFLINE,
			    hideLabel: true,
			    listeners: {
			        'change': {
			            fn: function (_checkbox, _checked) {
			                if (_checked) {
			                    this.Update(this.SKIP_IF_OFFLINE, 'Y');
			                    this.Update(this.EXECUTE_WHEN_ONLINE, 'N');
			                }
			                else {
			                    this.Update(this.SKIP_IF_OFFLINE, 'N');
			                    this.Update(this.EXECUTE_WHEN_ONLINE, 'Y');
			                }
			                //								var powerUpCheck = this.find('name', 'power_up_if_offline');
			                //								for (var i = 0; i < powerUpCheck.length; i++) {
			                //									if (!_checked) 
			                //										powerUpCheck[i].enable();
			                //									else 
			                //										powerUpCheck[i].disable();
			                //								}
			            },
			            scope: this
			        }
			    }
			}, {
			    xtype: 'checkbox',
			    name: 'power_up_if_offline',
			    boxLabel: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsPowerUpIfOffline + " " + Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsPowerUpIfOfflineExplaination,
			    inputValue: this.POWER_UP_IF_OFFLINE,
			    hidden: this.findMetaFieldInObject('disablepowerupifoffline', this.metaConfig).defaultValue == "true",
			    hideLabel: true,
			    listeners: {
			        'change': {
			            fn: function (_checkbox, _checked) {
			                if (_checked)
			                    this.Update(_checkbox.inputValue, 'Y');
			                else
			                    this.Update(_checkbox.inputValue, 'N');
			            },
			            scope: this
			        }
			    }
			}]

}, {
    xtype: 'fieldset',
    checkboxToggle: true,
    checkboxName: 'exclude_times',
    name: 'exclude_times_section',
    title: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsExcludeTimeRange,
    autoHeight: true,
    border: true,
    style: 'border: 0px; padding-left: 0px',
    bodyStyle: 'padding-left: 15px',
    listeners: {
        'expand': {
            fn: function (_p) {
                this.Update('excludetimerange', 'Y');
            },
            scope: this
        },
        'collapse': {
            fn: function (_p) {
                this.Update('excludetimerange', 'N');
            },
            scope: this
        }
    },
    items: [{
        xtype: 'timefield',
        format: ShellFinder().Date.DefaultTimeFormat,
        name: 'start_exclusion',
        fieldLabel: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsFrom,
        width: 260,
        value: Ext.Date.clearTime(new Date()),
        listeners: {
            'change': {
                fn: function (_field, _newVal, _oldVal) {
                    var date = Ext.Date.parse(_newVal, _field.format);
                    if (!date) {
                        date = ParseDate(_newVal, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                    }
                    this.Update('excludetimefrom', Ext.Date.format(this.correctDateToServerTime(date), 'c'));
                },
                scope: this
            },
            'select': {
                fn: function (_field, value, options) {
                    _field.setValue(value);
                    var date = Ext.Date.parse(value, _field.format);
                    if (!date) {
                        date = ParseDate(value, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                    }
                    this.Update('excludetimefrom', Ext.Date.format(this.correctDateToServerTime(date), 'c'));
                },
                scope: this
            }
        }
    }, {
        xtype: 'timefield',
        format: ShellFinder().Date.DefaultTimeFormat,
        name: 'end_exclusion',
        fieldLabel: Ext.ux.LangMgr.SchedulerControl.ExecutionOptionsThrough,
        width: 260,
        value: Ext.Date.clearTime(new Date()),
        listeners: {
            'change': {
                fn: function (_field, _newVal, _oldVal) {
                    var date = Ext.Date.parse(_newVal, _field.format);
                    if (!date) {
                        date = ParseDate(_newVal, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                    }
                    this.Update('excludetimeto', Ext.Date.format(this.correctDateToServerTime(date), 'c'));
                },
                scope: this
            },
            'select': {
                fn: function (_field, value, options) {
                    _field.setValue(value);
                    var date = Ext.Date.parse(value, _field.format);
                    if (!date) {
                        date = ParseDate(value, _field.format, ShellFinder().Date.DefaultAlternateFormats);
                    }
                    this.Update('excludetimeto', Ext.Date.format(this.correctDateToServerTime(date), 'c'));
                },
                scope: this
            }
        }
    }]
}]
        }


        this.items = [];

        /*
        * This hidden item is going to serve as a proxy to the form field.  This single control is going to get setValue()
        * called on it from a form, with the entire data object for the control.  As such, we'll override the setValue to call
        * into the scheduler's setValue so that all the control's are properly populated.  Likewise, we're going to validate
        * through the same mechanism to determine if the control is valid before saving it to the server
        */
        var me = this;
        this.items.push({
            hidden: true,
            items: {
                xtype: 'textfield',
                name: this.objectName,
                setValue: function (_model) {
                    if (!_model) {
                        return;
                    }
                    Ext.defer(me.setSchedulerModel, 1, me, [_model]);
                },
                validate: function () {
                    return me.validateScheduler();
                }

            }
        });

        //Add in the Schedule Object that has been previously configured properly
        this.items.push(schedule);

        //Determine if the Execution Options section should be presented to the user
        if (this.findMetaFieldInObject('includeexecution', this.metaConfig).defaultValue == "true") this.items.push(this.executionOptions);

        this.callParent(arguments);
    },

    onRender: function (ct, pos) {
        this.callParent(arguments);
        //			this.setSchedulerModel.defer(100, this, [this.dataConfig]);
    },

    //Private methods
    validateScheduler: function () {
        //RULE: ensure the run date/time is past now
        //This case is actually going to be handled by hermes.  It means that if you schedule something to occur in the past,
        //that we are going to schedule it to run now.  Possibly we might want to warn the user about this, but it shouldn't
        //invalidate the schedule
        var pastNow = true;

        var windowValid = this.validateDistributionWindow();

        var weeklyValue = this.validateWeeklySelections();

        return pastNow && windowValid && weeklyValue;
    },

    validateDistributionWindow: function () {
        //RULE: ensure the distribution window is less than the recurrence interval
        //If the distribution is set to 1 Day, and we're scheduling something to run every hour, we'll get into some sticky
        //situations.  Just make sure that the interval isn't larger than the recurrence.
        var windowValid = true;
        var scheduler = this.GetSchedulerDataModel();
        if (scheduler) {
            var recurrenceType = scheduler['recurrencetype'];

            var distributionTime = 0;
            var distributionInterval = this.MINUTES;

            var distributionTimes = this.find('name', 'distribution_window_value');
            for (var i = 0; i < distributionTimes.length; i++)
                if (distributionTimes[i].isVisible()) distributionTime = distributionTimes[i].getValue();
            distributionIntervals = this.find('name', 'distribution_window_interval');
            for (var i = 0; i < distributionIntervals.length; i++)
                if (distributionIntervals[i].isVisible()) distributionInterval = distributionIntervals[i].getValue();

            switch (distributionInterval) {
                case this.MINUTES:
                    //do nothing
                    break;
                case this.HOURS:
                    //convert to minutes
                    distributionTime = distributionTime * 60;
                    break;
                case this.DAYS:
                    //convert to minutes
                    distributionTime = distributionTime * 24;
                    distributionTime = distributionTime * 60;
                    break;
            }

            switch (recurrenceType) {
                case this.ONCE:
                    //do nothing, we're good to go because its not going to recur ever :)
                    break;
                case this.MINUTELY:
                    //ensure that the window is less than x minutes where x is the "recur every" number
                    var recur_minutes = scheduler['recurringminutesinterval'];
                    windowValid = recur_minutes >= distributionTime;
                    break;
                case this.HOURLY:
                    //ensure that the window is less than x hours where x is the "recur every" number
                    var recur_hours = scheduler['recurringhoursinterval'];
                    windowValid = ((recur_hours * 60) >= distributionTime);
                    break;
                case this.DAILY:
                    //ensure that the window is less than x days where x is the "recur every" number
                    var recur_days = scheduler['recurringdaysinterval'];
                    windowValid = ((recur_days * 24 * 60) >= distributionTime);
                    break;
                case this.WEEKLY:
                    //ensure that the window is less than x weeks where x is the "recur every" number
                    var recur_weeks = scheduler['recurringweeksinterval'];
                    windowValid = ((recur_weeks * 7 * 24 * 60) >= distributionTime);
                    break;
                case this.MONTHLY:
                    //ensure that the window is less than x months where x is the "recur every" number
                    var recur_months = scheduler['recurringmonthsinterval'];
                    windowValid = ((recur_months * 30 * 7 * 24 * 60) >= distributionTime);
                    break;
                case this.YEARLY:
                    //ensure that the window is less than x years where x is the "recur every" number
                    var recur_years = scheduler['recurringyearsinterval'];
                    windowValid = ((recur_years * 12 * 30 * 7 * 24 * 60) >= distributionTime);
                    break;
            }

            if (!windowValid) {
                for (var i = 0; i < distributionIntervals.length; i++)
                    if (distributionIntervals[i].isVisible()) distributionIntervals[i].markInvalid(Ext.ux.LangMgr.SchedulerControl.DistributionWindowInvalid);
            }
            else
                for (var i = 0; i < distributionIntervals.length; i++)
                    if (distributionIntervals[i].isVisible()) distributionIntervals[i].clearInvalid();

            return windowValid;
        }
        return true;
    },

    validateWeeklySelections: function () {
        //RULE: if the weekly recurrence type is selected, then make sure that at least one day is selected
        //otherwise the user is not going to actually schedule anything to be run. 
        var weeklyValid = true;
        var scheduler = this.GetSchedulerDataModel();
        if (scheduler) {
            var recurrenceType = scheduler['recurrencetype'];
            if (recurrenceType == this.WEEKLY) {
                var daySelected = false;
                var daysOfWeek = this.find('name', 'days_of_the_week');
                for (var i = 0; i < daysOfWeek.length; i++) {
                    for (var j = 0; j < daysOfWeek[i].items.length && !daySelected; j++) {
                        var val = daysOfWeek[i].items.items[j].getValue();
                        if (val) daySelected = true;
                    }
                    if (!daySelected) {
                        daysOfWeek[i].markInvalid(Ext.ux.LangMgr.SchedulerControl.WeeklySelectionInvalid);
                    }
                    weeklyValid = daySelected;
                }
            }
        }
        return weeklyValid;
    },

    UpdateEndDateTime: function () {
        var scheduler = this.GetSchedulerDataModel();
        if (scheduler) {
            //grab the time and date from the controls
            var runAts = this.find('name', 'run_at');
            var dateValue = runAts[0].getValue();
            var dateFormat = runAts[0].format;
            var date = ParseDate(dateValue, dateFormat, ShellFinder().Date.DefaultAlternateFormats);
            var runAts2 = this.find('name', 'start_on');
            var date2 = runAts2[0].getValue();
            var startTime = ParseDate(date, 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);
            var startDate = ParseDate(date2, 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);

            //in case something has gone horribly wrong with the data, don't die
            if (!startDate) startDate = new Date();
            if (!startTime) startTime = new Date();

            //sync the startDate and startTime
            var startDateTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), startTime.getHours(), startTime.getMinutes(), startTime.getSeconds());


            //correct for server time difference if there is any
            startDateTime = this.correctDateToServerTime(startDateTime);

            this.Update('startdatefrom', Ext.Date.format(startDateTime, 'c'));
            this.Update('starttimefrom', Ext.Date.format(startDateTime, 'c'));

            var endDateTime = startDateTime;

            //now the endDateTime is set to the same as the start time,
            //we just need to add the proper interval from the distribution window and we're good to go
            var distributionTime = 0;
            var distributionInterval = this.MINUTES;

            var distributionTimes = this.find('name', 'distribution_window_value');
            for (var i = 0; i < distributionTimes.length; i++)
                if (distributionTimes[i].isVisible()) distributionTime = distributionTimes[i].getValue();
            var distributionIntervals = this.find('name', 'distribution_window_interval');
            for (var i = 0; i < distributionIntervals.length; i++)
                if (distributionIntervals[i].isVisible()) distributionInterval = distributionIntervals[i].getValue();

            switch (distributionInterval) {
                case this.MINUTES:
                    endDateTime = Ext.Date.add(endDateTime, ShellFinder().Date.MINUTE, distributionTime);
                    break;
                case this.HOURS:
                    endDateTime = Ext.Date.add(endDateTime, ShellFinder().Date.HOUR, distributionTime);
                    break;
                case this.DAYS:
                    endDateTime = Ext.Date.add(endDateTime, ShellFinder().Date.DAY, distributionTime);
                    break;
            }

            //Update the data island with this information
            this.Update('startdateto', Ext.Date.format(endDateTime, 'c'));
            this.Update('starttimeto', Ext.Date.format(endDateTime, 'c'));
        }
        this.validateDistributionWindow();
    },

    correctDateToServerTime: function (_date) {
        var newDate = Ext.Date.add(_date, ShellFinder().Date.MINUTE, ShellFinder().Date.calculatedOffset || 0);
        return newDate;
    },

    setSchedulerModel: function (_model) {
        var scheduler = _model.records ? eval("_model.records." + this.objectName + ".data[0]") : _model;
        if (scheduler) {
            //Set the Selected Recurrence Pattern Radio
            var recurrenceRadioArray = this.find('name', 'recurrenceOptions');
            for (var i = 0; i < recurrenceRadioArray.length; i++)
                for (var j = 0; j < recurrenceRadioArray[i].items.length; j++) {
                    if (recurrenceRadioArray[i].items.items[j].inputValue == scheduler['recurrencetype']) {
                        recurrenceRadioArray[i].items.items[j].setValue(true);
                        this.changeRecurrence(recurrenceRadioArray[i].items.items[j], true);
                    }
                    else
                        recurrenceRadioArray[i].items.items[j].setValue(false);
                }

            //Set the selected recurrence pattern's options
            var startTime = ParseDate(scheduler['starttimefrom'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);
            if (startTime) this.Update('starttimefrom', Ext.Date.format(startTime, 'c'));
            var startDate = ParseDate(scheduler['startdatefrom'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);
            if (startDate) this.Update('startdatefrom', Ext.Date.format(startDate, 'c'));
            var endTime = ParseDate(scheduler['starttimeto'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);
            if (endTime) this.Update('starttimeto', Ext.Date.format(endTime, 'c'));
            var endDate = ParseDate(scheduler['startdateto'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats);
            if (endDate) this.Update('startdateto', Ext.Date.format(endDate, 'c'));

            startDate.setHours(startTime.getHours());
            startDate.setMinutes(startTime.getMinutes());
            startDate.setSeconds(startTime.getSeconds());

            endDate.setHours(endTime.getHours());
            endDate.setMinutes(endTime.getMinutes());
            endDate.setSeconds(endTime.getSeconds());

            var distributionWindow = (Ext.Date.getElapsed(endDate, startDate) / 1000) / 60; //puts distribution into minutes
            if (scheduler.distribution) distributionWindow = scheduler.distribution / 60; //puts distribution into minutes
            var distInterval = this.MINUTES;
            if (distributionWindow >= 60) {
                distributionWindow = distributionWindow / 60;
                distInterval = this.HOURS;
            }
            if (distributionWindow >= 24 && distInterval != this.MINUTES) { //if this fell into the >= 60 logic then check if we are dealing with days
                distributionWindow = distributionWindow / 24;
                distInterval = this.DAYS;
            }

            /*
            * If the scheduler has no ID, then we are working with a new schedule.
            * In this case, we need to take the start datetime and bump them up to now,
            * then update the end datetime accordingly
            */
            //			if (!scheduler.id || scheduler.id.length == 0) {
            //				startDate = new Date();
            //				startTime = new Date();
            //				this.Update('startdatefrom', this.correctDateToServerTime(startDate).format('c')));
            //				this.Update('starttimefrom', this.correctDateToServerTime(startDate).format('c'));
            //			}

            var runAts = this.find('name', 'run_at');
            for (var i = 0; i < runAts.length; i++)
                runAts[i].setValue(startTime);

            //Calculate value for distribution window
            var distributionValue = this.find('name', 'distribution_window_value');
            for (var i = 0; i < distributionValue.length; i++)
                distributionValue[i].setValue(distributionWindow);
            var distributionInterval = this.find('name', 'distribution_window_interval');
            for (var i = 0; i < distributionInterval.length; i++)
                distributionInterval[i].setValue(distInterval);

            this.UpdateEndDateTime();

            /*
            * You thought we were done with the scheduler not having an id huh?  Not quite.
            * We need to update the end datetime accordingly after we update the distribution
            * window controls otherwise the end datetime will be set to 1 hr by default.
            */
            //			if (!scheduler.id || scheduler.id.length == 0) {
            //				this.UpdateEndDateTime();
            //			}

            //Recurrence Options

            //once
            //This is only the standard Run At configuration (handled above) and then the starting date (handled above also)
            var everyMinutes = this.find('name', 'run_minutely_every');
            for (var i = 0; i < everyMinutes.length; i++)
                everyMinutes[i].setValue(scheduler['recurringminutesinterval']);

            //hourly
            var everyHours = this.find('name', 'run_hourly_every');
            for (var i = 0; i < everyHours.length; i++)
                everyHours[i].setValue(scheduler['recurringhoursinterval']);

            //daily
            var everyDays = this.find('name', 'run_daily_every');
            for (var i = 0; i < everyDays.length; i++)
                everyDays[i].setValue(scheduler['recurringdaysinterval']);

            //weekly
            var everyWeeks = this.find('name', 'run_weekly_every');
            for (var i = 0; i < everyWeeks.length; i++)
                everyWeeks[i].setValue(scheduler['recurringweeksinterval']);

            var daysOfWeek = this.find('name', 'days_of_the_week');
            for (var i = 0; i < daysOfWeek.length; i++)
                for (var j = 0; j < daysOfWeek[i].items.length; j++)
                    switch (daysOfWeek[i].items.items[j].inputValue) {
                    case this.SUNDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['sundayflag'] == 'Y');
                        break;
                    case this.MONDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['mondayflag'] == 'Y');
                        break;
                    case this.TUESDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['tuesdayflag'] == 'Y');
                        break;
                    case this.WEDNESDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['wednesdayflag'] == 'Y');
                        break;
                    case this.THURSDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['thursdayflag'] == 'Y');
                        break;
                    case this.FRIDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['fridayflag'] == 'Y');
                        break;
                    case this.SATURDAY:
                        daysOfWeek[i].items.items[j].setValue(scheduler['saturdayflag'] == 'Y');
                        break;
                }

            //monthly
            var everyMonths = this.find('name', 'run_monthly_every');
            for (var i = 0; i < everyMonths.length; i++)
                everyMonths[i].setValue(scheduler['recurringmonthsinterval']);

            var monthOccurrences = this.find('name', 'month_day');
            for (var i = 0; i < monthOccurrences.length; i++)
                monthOccurrences[i].setValue(scheduler['monthday']);

            if (scheduler['monthlyintervaltype'] == null) scheduler['monthlyintervaltype'] = this.MONTHLY_ON_DAY;
            var monthType = this.find('name', 'monthly');
            for (var i = 0; i < monthType.length; i++)
                monthType[i].setValue(monthType[i].inputValue == scheduler['monthlyintervaltype']);

            var monthSpecificOccurence = this.find('name', 'monthly_specific_occurrence');
            for (var i = 0; i < monthSpecificOccurence.length; i++)
                monthSpecificOccurence[i].setValue(scheduler['monthlyspecificoccurrence']);

            var monthSpecificDay = this.find('name', 'monthly_specific_day');
            for (var i = 0; i < monthSpecificDay.length; i++)
                monthSpecificDay[i].setValue(scheduler['monthlyspecificday']);

            //yearly
            var everyYears = this.find('name', 'run_yearly_every');
            for (var i = 0; i < everyYears.length; i++)
                everyYears[i].setValue(scheduler['recurringyearsinterval']);

            if (scheduler['yearlyintervaltype'] == null) scheduler['yearlyintervaltype'] = this.YEARLY_ON_DAY;
            var yearlyType = this.find('name', 'yearly');
            for (var i = 0; i < yearlyType.length; i++)
                yearlyType[i].setValue(yearlyType[i].inputValue == scheduler['yearlyintervaltype']);

            var yearSpecificMonth = this.find('name', 'yearly_specific_month');
            for (var i = 0; i < yearSpecificMonth.length; i++)
                yearSpecificMonth[i].setValue(scheduler['yearlyspecificmonth']);

            var yearDay = this.find('name', 'yearly_day');
            for (var i = 0; i < yearDay.length; i++)
                yearDay[i].setValue(scheduler['yearday']);

            var yearSpecificOccurence = this.find('name', 'year_specific_occurrence');
            for (var i = 0; i < yearSpecificOccurence.length; i++)
                yearSpecificOccurence[i].setValue(scheduler['yearlyspecificoccurrence']);

            var yearSpecificDay = this.find('name', 'year_specific_day');
            for (var i = 0; i < yearSpecificDay.length; i++)
                yearSpecificDay[i].setValue(scheduler['yearlyspecificday']);

            var yearSpecificMonth2 = this.find('name', 'year_specific_month2');
            for (var i = 0; i < yearSpecificMonth2.length; i++)
                yearSpecificMonth2[i].setValue(scheduler['yearlyspecificmonth2']);
            //End Recurrence Options

            //Set the Start/End options

            //Start On ShellFinder().Date
            var startDates = this.find('name', 'start_on');
            for (var i = 0; i < startDates.length; i++)
                startDates[i].setValue(startDate);

            //End After radio selection
            var endAfters = this.find('name', 'ending_after');
            for (var i = 0; i < endAfters.length; i++)
                endAfters[i].setValue(endAfters[i].inputValue == scheduler['rangeofrecurrencetype']);

            //End After radio options
            var endAfterOccurrences = this.find('name', 'ending_after_occurrences');
            for (var i = 0; i < endAfterOccurrences.length; i++)
                endAfterOccurrences[i].setValue(scheduler['rangeofrecurrenceendafterinterval']);
            var endAfterDate = this.find('name', 'ending_at_date');
            for (var i = 0; i < endAfterDate.length; i++)
                endAfterDate[i].setValue(ParseDate(scheduler['rangeofrecurrenceenddatetime'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats));
            var endAfterTime = this.find('name', 'ending_at_time');
            for (var i = 0; i < endAfterTime.length; i++)
                endAfterTime[i].setValue(ParseDate(scheduler['rangeofrecurrenceenddatetime'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats));

            //End Start/End Options

            //Execution Options
            //Offline Radio
            var offlineRadios = this.find('name', 'if_offline');
            for (var i = 0; i < offlineRadios.length; i++)
                offlineRadios[i].setValue(scheduler[offlineRadios[i].inputValue] == 'Y');

            //PowerUp Check
            var powerUp = this.find('name', 'power_up_if_offline');
            for (var i = 0; i < powerUp.length; i++)
                powerUp[i].setValue(scheduler[powerUp[i].inputValue] == 'Y');

            //Exclusion Check
            var exclusionCheck = this.find('name', 'exclude_times_section');
            for (var i = 0; i < exclusionCheck.length; i++) {
                if (scheduler['excludetimerange'] == 'Y')
                    exclusionCheck[i].expand();
                else
                    exclusionCheck[i].collapse();
            }
            //From
            var excludeFrom = this.find('name', 'start_exclusion');
            for (var i = 0; i < excludeFrom.length; i++) {
                var excFrom = ParseDate(scheduler['excludetimefrom'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats) || new Date();
                if (excFrom) {
                    excludeFrom[i].setValue(excFrom);
                    this.Update('excludetimefrom', Ext.Date.format(this.correctDateToServerTime(excFrom), 'c'));
                }
            }
            //Through	
            var excludeTo = this.find('name', 'end_exclusion');
            for (var i = 0; i < excludeTo.length; i++) {
                var excTo = ParseDate(scheduler['excludetimeto'], 'n/j/Y g:i:s A', ShellFinder().Date.DefaultAlternateFormats) || new Date();
                if (excTo) {
                    excludeTo[i].setValue(excTo);
                    this.Update('excludetimeto', Ext.Date.format(this.correctDateToServerTime(excTo), 'c'));
                }
            }
            //End Execution Options

            //If we are in the framework, then we need to make sure that all that stuff we just did
            //didn't make the island dirty.
            if (Kaseya && Kaseya.web && Kaseya.web.managers && ShellFinder().Kaseya.web.managers.PageManager) {
                ShellFinder().Kaseya.web.managers.PageManager.manuallyCleanIsland(this.pageId, this.pageId);
            }
        }
    },

    changeRecurrence: function (_recurrence, _checked) {
        if (_checked) {
            switch (_recurrence.inputValue) {
                case this.ONCE:
                    this.interval.setText('');
                    this.startEndSection.hide();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.ONCE);
                    break;

                case this.MINUTELY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Minutes);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.MINUTELY);
                    break;

                case this.HOURLY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Hours);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.HOURLY);
                    break;

                case this.DAILY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Days);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.DAILY);
                    break;

                case this.WEEKLY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Weeks);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.WEEKLY);
                    break;

                case this.MONTHLY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Months);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.MONTHLY);
                    break;

                case this.YEARLY:
                    this.interval.setText(Ext.ux.LangMgr.SchedulerControl.Years);
                    this.startEndSection.show();
                    this.scheduleOptions.getLayout().setActiveItem(this.id + '_' + this.YEARLY);
                    break;
            }
            this.scheduleOptions.doLayout();
            //Now update the underlying data island with the recurrence change
            this.Update('recurrencetype', _recurrence.inputValue);
        }
    },

    Update: function (_fieldName, _newValue) {
        if (eval("ShellFinder().Kaseya.web.managers.PageManager.getModel( this.pageId, this.dataIslandId )." + this.formReaderRoot)) {
            ShellFinder().Kaseya.web.managers.PageManager.setModelItemValue(this.pageId, this.dataIslandId, this.formReaderRoot, _fieldName.toLowerCase(), _newValue);
        }
    },

    GetSchedulerDataModel: function () {
        eval("var data = ShellFinder().Kaseya.web.managers.PageManager.getModel( this.pageId, this.dataIslandId )." + this.formReaderRoot);
        return data.data[0];
    }
});
